#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 15 03:25:09 2020
测试数据转成csv; 字段和训练数据不一样
@author: ua17
"""
from process2 import *
from operator import itemgetter
from io import StringIO
import pandas as pd
import sys
import itertools



def read_mapper_output(file, separator = '\t'):
    for line in file:
        yield line.rstrip().split(separator,1)



input_seqs = open("test_data.csv",'r')
input_seqs.readline()
kv_sep = ','

out = "test_out.csv"
fw = open(out, 'w')
fw.write(",".join(columns3) + "\n")
fw.close()

print("start")

stdin_generator=read_mapper_output(input_seqs, kv_sep)
for key, values in itertools.groupby(stdin_generator,itemgetter(0)):
    print(key, end="\t")
    new_lines = []
    all_v = '\n'.join([ key_1 +","+ value_1 for key_1, value_1 in values])

    merged = merge_block(StringIO(all_v))

    new_v = process_block(merged)
    new_lines.extend(new_v)
    print(" & {} fields to_csv ".format(len(new_v[0])) )
    df = pd.DataFrame(new_v)
    df.to_csv(out, index=False, header=False, mode='a', float_format="%.5f")

